<?
//print_r($_POST);

// Convert to simple variables
//	if (isset($HTTP_POST_VARS['clientID']))
//		$clientID = $HTTP_POST_VARS['clientID'];
if (isset($HTTP_POST_VARS['txtNumber']))
$txtNumber = trim($HTTP_POST_VARS['txtNumber']);
if (isset($HTTP_POST_VARS['cmbIdType']))
$cmbIdType = trim($HTTP_POST_VARS['cmbIdType']);
if (isset($HTTP_POST_VARS['clientFirstName']))
$clientFirstName = trim($HTTP_POST_VARS['clientFirstName']);
if (isset($HTTP_POST_VARS['clientLastName']))
$clientLastName = trim($HTTP_POST_VARS['clientLastName']);
if (isset($HTTP_POST_VARS['operatorFirstName']))
$operatorFirstName = $HTTP_POST_VARS['operatorFirstName'];
if (isset($HTTP_POST_VARS['operatorLastName']))
$operatorLastName = $HTTP_POST_VARS['operatorLastName'];
if (isset($HTTP_POST_VARS['operatorReference']))
$operatorReference = $HTTP_POST_VARS['operatorReference'];

// to remove all the hyphens,spaces and ots in id number
$idnumhyphen=explode('-',$txtNumber);
$txtNumber = "";
for ($i=0;$i<count($idnumhyphen);$i++)
{
	$txtNumber=$txtNumber."". $idnumhyphen[$i];
}

$idnumspace=explode(' ',$txtNumber);
$txtNumber = "";
for ($i=0;$i<count($idnumspace);$i++)
{
	$txtNumber=$txtNumber."". $idnumspace[$i];
}

$idnumdot=explode('.',$txtNumber);
$txtNumber = "";
for ($i=0;$i<count($idnumdot);$i++)
{
	$txtNumber=$txtNumber."". $idnumdot[$i];
}

$idnumslash=explode('/',$txtNumber);
$txtNumber = "";
for ($i=0;$i<count($idnumslash);$i++)
{
	$txtNumber=$txtNumber."". $idnumslash[$i];
}
//end


$noIDSelected = "Select ID Type";
$orderBy = " ORDER BY a.surname, a.givenname ";
$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorReference Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";

//$clientID = substr($cmbIdType, 0, 3) . $txtNumber;
if ($cmbIdType == $noIDSelected)
{
	$identification_type = "";
}
else
{
	$identification_type = 	getIdFromListBox("er_identification_type","identification_type", $cmbIdType);
}

if((strlen($identification_type)==0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)==0) && (strlen($txtNumber)==0))
{
	//print "<a href=\"SearchBasic.php\">";
	//print "<img border=\"0\" src=\"images/BasicSearch.gif\" align=\"right\"> </a>";
	echo "Please enter Search criteria<br />";
	include './pages/search_advance.php';
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)==0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname, b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE b.identification_no=$identification_type  $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> ";
	//print "1";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)==0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname, b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.givenname LIKE '%$clientFirstName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for Reference Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> ";
	//print "2";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname, b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE a.surname LIKE '%$clientLastName%'  $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for LastName <b>'$clientLastName'</b>";
	//print "3";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)==0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname, b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE (a.id_reference_no LIKE '%$txtNumber%') $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for Ref. No <b>'$txtNumber'</b>";
	//print "4";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)==0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorFirstName (a.givenname LIKE '%$clientFirstName%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> ";
	//print "5";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorLastName (a.surname LIKE '%$clientLastName%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
	//print "6";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)==0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorReference Ref. No <b>'$txtNumber'</b> ";
	//print "7";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.givenname LIKE '%$clientFirstName%') $operatorLastName (a.surname LIKE '%$clientLastName%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for First Name <b>'$clientFirstName'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
	//print "8";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)==0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.givenname LIKE '%$clientFirstName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> ";
	//print "9";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.surname LIKE '%$clientLastName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for Ref. No <b>'$txtNumber'</b> $operatorLastName Last Name <b>'$clientLastName'</b> ";
	//print "10";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorFirstName (a.givenname LIKE '%$clientFirstName%') $operatorLastName (a.surname LIKE '%$clientLastName%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
	//print "11";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)==0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorLastName (a.surname LIKE '%$clientLastName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorReference Ref. No <b>'$txtNumber'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
	//print "12";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)==0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorFirstName (a.givenname LIKE '%$clientFirstName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorReference Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> ";
	//print "13";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.givenname LIKE '%$clientFirstName%') $operatorLastName (a.surname LIKE '%$clientLastName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
	//print "14";
}
elseif((strlen($identification_type)<>0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)<>0) && (strlen($txtNumber)<>0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.identification_no =$identification_type) $operatorFirstName (a.givenname LIKE '%$clientFirstName%') $operatorLastName (a.surname LIKE '%$clientLastName%') $operatorReference (a.id_reference_no LIKE '%$txtNumber%')) $orderBy";
	$searchCriteria = "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorReference Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
	//print "15";
}
elseif((strlen($identification_type)==0) && (strlen($clientFirstName)<>0) && (strlen($clientLastName)==0) && (strlen($txtNumber)==0))
{
	$query = "SELECT  a.client_id, a.id_reference_no, a.surname, a.givenname,b.identification_type FROM er_client as a JOIN er_identification_type as b ON a.identification_no = b.identification_no  WHERE ((a.givenname LIKE '%$clientFirstName%')) $orderBy";
	$searchCriteria = "Searched for First Name '$clientFirstName'";
	//print "16";
}
else
{
	print "<span style=\"font-weight: normal\">Searched for ID Type <b>'$cmbIdType'</b> $operatorReference Ref. No <b>'$txtNumber'</b> $operatorFirstName First Name <b>'$clientFirstName'</b> $operatorLastName Last Name <b>'$clientLastName'</b>";
}

if (isset($query)) {
	include("submit_search.php");
}

?>
 <!--   <script language="javascript" src="clientsearchnav.js"></script>-->